<?php
class Observer implements SplSubject { 
    protected $_observers;
	protected $_params;
	protected $_status;
	//附加执行的类
    public function attach(SplObserver $observer){
		if($this->_observers==NULL) $this->_observers = new SplObjectStorage(); 
        $this->_observers->attach($observer); 
    }
	//移除执行的类
    public function detach(SplObserver $observer){
        $this->_observers->detach($observer);
    }
	//动作执行
    public function notify(){
        foreach ($this->_observers as $observer) { 
            $observer->update($this); 
        }
		$this->_observers = new SplObjectStorage();
    } 
	//获取执行的状态
	public function getStatus(){
		return $this->_status;
    }
	//设置执行的状态
    public function setStatus($info){
        return $this->_status=$info;
    }	
	//获取参数
    public function getParams(){
        return $this->_params;
    }
	public function addParams($key, $val) {
		$this->_params[$key] =  $val;
    }
    public function setParams($params){
        $this->_params=$params;
    }
    public function clearParams(){
        $this->_params=NULL;
    }
	//执行
    public function execute($params=''){
		if($params!=''){
			foreach($params as $k=>$v) $this->_params[$k]=$v;
		}
        $this->notify();
    }

}